import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:给定一个不含重复数字的数组 nums ，返回其 所有可能的全排列 。你可以 按任意顺序 返回答案。
 * User: wangxin
 * Date: 2025-05-26
 * Time: 21:10
 */
public class Test {
    public List<List<Integer>> ret ;
    public List<Integer>  path;
    public boolean[] check;
    public List<List<Integer>> permute(int[] nums) {
        ret = new ArrayList<>();
        path = new ArrayList<>();
        check = new boolean[nums.length];

        dfs(nums);

        return ret;
    }
    public void dfs(int[] nums){
        if(path.size() == nums.length){
            ret.add(new ArrayList<>(path));
            return;
        }
        for(int i = 0;i < nums.length;i++){
            if(check[i] == false){
                path.add(nums[i]);
                check[i] = true;
                dfs(nums);
                check[i] = false;
                path.remove(path.size()-1);
            }
        }
    }
}
